﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using LibFriesland_Campina_CRM;

namespace WebServiceFriesland_Campina_CRM
{
    /// <summary>
    /// Summary description for FCShopperWS
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class FCShopperWS : System.Web.Services.WebService
    {
        [WebMethod]
        //Lay danh sach Shopper
        public List<BizShopper> getAll()
        {
            return BizShopper.getAll();
        }

        [WebMethod]
        //Lay danh sach Shopper by NA
        public List<BizShopper> getShopperbyNA(string pBy_na)
        {
            return BizShopper.getShopperbyNA(pBy_na);
        }

        [WebMethod]
        //Lay danh sach Shopper cua NA tai mot Shop
        public List<BizShopper> getShopperbyNAShop(string pBy_na, string pBy_shop)
        {
            return BizShopper.getShopperbyNA(pBy_na, pBy_shop);
        }

        [WebMethod]
        //Cap nhat thong tin khach hang
        public int updateShopper(string pBy_na, string poName, string poNickname, string poPhone, string poAddress, string poRelativesName, string pnName, string pnNickname, string pnPhone, string pnAddress, string pnRelativesName, string pnRelativesYear_born)
        {
            //Cap nhat thong tin 
            BizShopper shopper = new BizShopper(-1, pnName, pnNickname, pnPhone, pnAddress);
            shopper.shopper_numid = BizShopper.getShopperNumID(pBy_na, poName, poNickname, poPhone, poAddress);
            BizRelatives relatives = new BizRelatives(-1, pnRelativesName, (pnRelativesYear_born.Trim() != "") ? Convert.ToInt32(pnRelativesYear_born) : 0, shopper.shopper_numid);
            
            relatives.relatives_numid = BizRelatives.getRelativesNumID(poRelativesName, shopper.shopper_numid);
            return shopper.updateShopper(relatives);
        }
    }
}
